<?php
ob_start();
error_reporting(E_ALL ^ E_NOTICE);
session_start();
$_SESSION['madv'] = $_POST['tendv'];
$_SESSION['congsuat'] = $_POST['congsuat'];


include_once($_SERVER['DOCUMENT_ROOT'] . '/htqlmba/configs/database.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/htqlmba/controls/c_thongKe.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/htqlmba/libraries/PHPExcel_1.7.9_doc/Classes/PHPExcel.php');

/** PHPExcel_Writer_Excel2007 */
/* include_once($_SERVER['DOCUMENT_ROOT'].'/nien luan_THAO_BAO_CAO_PART/nien luan/thong ke theo cong suat 2/PHPExcel_1.7.9_doc/Classes/PHPExcel/Writer/Excel2007.php');
  include_once($_SERVER['DOCUMENT_ROOT'].'/nien luan_THAO_BAO_CAO_PART/nien luan/thong ke theo cong suat 2/PHPExcel_1.7.9_doc/Classes/PHPExcel/IOFactory.php'); */
?>
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Demo Ajax</title>
        <link href="/htqlmba/libraries/css/capnhatdv.css" type="text/css" rel="stylesheet">
        <script type="text/javascript" src="/htqlmba/views/v_javascript_cs.js"></script>
    </head>
    <body>
        <form name="formthongkecs" method="post" action="">
            <table align="center" class="TableField2" width="600" border="0">
                <tr>
                    <td align=center class="TableHeader1"> &equiv; Tùy chọn thống kê theo công suất</td>
                </tr>
                <tr >
                    <td bgcolor="#dae9f3">
                        <table width="300" border="0" align="center">
                            <tr>
                                <td height="5px" colspan="2">&nbsp;</td>
                            </tr>
                            <!--Sua tai day: them vao-->
                           
                           <?php
                            
                            $db = new database();
			$db->setQuery("select * from don_vi as dv, tai_khoan as tk where dv.MA_DON_VI = tk.MA_DON_VI and tk.MA_DON_VI = ".$_SESSION['nmadv']);
			$result = $db->fetchAll();			
			 $row = mysql_fetch_array($result);
			 if ($row['QUYEN'] == 2 || $row['QUYEN']==1){
                            
                            
                            echo "<tr>";
                               echo "<td width='120' align='right' class='TableField2'>Đơn Vị: </td>";
                                echo "<td width='200' align='left'>";
                                    
                                   echo "<select name='tendv' id='mdv' style='width: 200px'>";
                                     echo  " <option value='tatca'>Tất cả</option>";
                                        $db->setQuery("select * from don_vi as dv, tai_khoan as tk where dv.MA_DON_VI = tk.MA_DON_VI  and tk.QUYEN = 3");

                                        $result = $db->fetchAll();

                                        while ($row = mysql_fetch_array($result)) {

                                            echo "<option value=\"" . $row['MA_DON_VI'] . "\">" . $row['TEN_DON_VI'] . "</option>";
                                        }

                                   echo " </select>";
                                    
                                echo "</td>";
                           echo " </tr>";
                            }
                            else {
                            echo "<input type='hidden' id='mdv' name='tendv' value='".$row['MA_DON_VI']."'/>";
                            }
                            
                            ?>
                            
                            <!--Het sua-->
                            <tr>
                                <td width="120" align="right" class="TableField2">Công Suất: </td>
                                <td width="200" align="left">
                                    <select name="congsuat" id="congsuat" style="width: 100px">
                                        <option value="tatca"\">Tất cả</option>;
                                        <?php
                                        $db = new database();
                                        $db->setQuery("select * from may_bien_ap  group by CONG_SUAT");
                                        $re = $db->fetchAll();

                                        while ($row = mysql_fetch_array($re)) {
                                            echo "<option value=\"" . $row['CONG_SUAT'] . "\">" . $row['CONG_SUAT'] . "</option>";
                                        }
                                        ?>
                                    </select>
                                </td>
                            </tr>

                            <tr>
                                <td height="5px" colspan="2">&nbsp;</td>
                            </tr>
                            <tr>
                                <td colspan="2" align="center">
                                    <input name="thongke" type="button" id="thongke" onClick="thongkecs()" value="Thống kê">
                                    &nbsp;&nbsp;

                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>                   
            <!-- Dưới đây là định vị cái chỗ để kết quả xuất hiện -->
            <div id="xuathienchonay">    
            </div>
            <!--<input type="submit" name="inexcel" id="button" value="In file excel">-->
        </form>
        <!--kiem tra in excel-->            
    </body>
</html>